<?php
    	header('Content-type:text/json;charset=utf-8');
	$data=array();
    	$mysqli = new mysqli("127.0.0.1", "root", "20155222", "lzj");
	if ($mysqli->connect_errno) {
	    printf("Connect failed: %s\n", $mysqli->connect_error);
	    exit();
	}
	$sql="select postid,title from posts;";
	if ($result = $mysqli->query($sql)) {
		for($i=0;$i<$result->num_rows;$i++){
		$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
		$data[current($row)]=next($row);
		next($result);
	}
	$result->close();
	}
	
   	
   	echo json_encode($data);//输出json数据
	$mysqli->close();
?>
